/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package genotypes;

import java.util.Random;
import misc.Evaluation;

/**
 *
 * @author rusak
 */
public class Angles {

    private int size;
    private double angles[];
    private Evaluation evaluation;
    

    public Angles(double[] angles) {
        this.angles = angles;
        size = angles.length;
    }

    public boolean isAcceptable() {
        return evaluation.getNoOFIntersections() == 0;
    }

    public double getAngleAt(int i) {
        return angles[i];
    }

    public void setAngleAt(int i, double v) {
        angles[i] = v;
    }

    public double getDistanceToDest() {
        return evaluation.getDistanceToDest();
    }

    public double[] getAngles() {
        return angles;
    }

    public void setAngles(double angles[]) {
        this.angles = angles;
    }

    public void setEvaluation(Evaluation evaluation) {
        this.evaluation = evaluation;
    }

    public static Angles randomAngles(int size, double[][] limtations) {
        double result[] = new double[size];
        Random r = new Random();
        double min, max, scale, ran;
        for (int i = 0; i < size; i++) {
            min = limtations[i][0];
            max = limtations[i][1];
            scale = max - min;
            ran = r.nextDouble();
            result[i] = ran * scale + min;
        }
        return new Angles(result);
    }

    @Override
    public String toString() {
        StringBuilder s = new StringBuilder();
        s.append("[");
        for(int i=0;i<size;i++) {
            s.append("| "+angles[i]+" ");
        }
        s.append("]");
        return s.toString();
    }
    
    public Angles copy() {
        Angles result = new Angles(angles);
        result.setEvaluation(evaluation);
        return result;
    }
    
    public int getObstaclesOnTheWay() {
        return evaluation.getNoOFIntersections();
    }
    
    public int getDetourLength() {
        return 0;
    }
}
